/********************************************************************************
 * @File name: mutex.c
 * @Author: Letitia-Ron/PU-TONG/ArsSama
 * @Version: 1.0
 * @Date: 2023-4-15
 * @Description: mutex
 ********************************************************************************/

#include "mutex.h"
#include "esp_err.h"
#include "esp_log.h"

static const char *TAG = "mutex";

/* defien mutex start */
SemaphoreHandle_t local_time_mutex = NULL;
SemaphoreHandle_t cpu_temp_mutex = NULL;
/* defien mutex end */

/**
 * @brief create_mutex 创建互斥锁
 *
 */
void create_mutex(void)
{
    /* create mutex_1 start */
    local_time_mutex = xSemaphoreCreateMutex();
    if (local_time_mutex != NULL)
    {
        ESP_LOGI(TAG, "Creat local_time_mutex successfully");
    }
    else
    {
        /* error handler begin */
        ESP_LOGE(TAG, "Creat local_time_mutex error. err msg->%s,,%s", __FILE__, __func__);
        vSemaphoreDelete(local_time_mutex);
        /* error handler end */
    }
    /* create mutex_1 end */

    /* create mutex_2 start */
    cpu_temp_mutex = xSemaphoreCreateMutex();
    if (cpu_temp_mutex != NULL)
    {
        ESP_LOGI(TAG, "Creat cpu_temp_mutex successfully");
    }
    else
    {
        /* error handler begin */
        ESP_LOGE(TAG, "Creat cpu_temp_mutex error. err msg->%s,,%s", __FILE__, __func__);
        vSemaphoreDelete(cpu_temp_mutex);
        /* error handler end */
    }
    /* create mutex_2 end */
}
